﻿@model Lehnet.Models.Personel
@{Html.RenderPartial("FancyRequireScripts");}
<script>

    $(document).ready(function () {
        getAllPersonelAjax();

        $(".various").fancybox({
            maxWidth: 800,
            maxHeight: 600,
            fitToView: false,
            width: '70%',
            height: '70%',
            autoSize: false,
            closeClick: true,
            openEffect: 'elastic',
            closeEffect: 'fade',
            modal: true
        });
    });
    function confirmDelete(personelId) {
        if (confirm("Kaydı silmek istediğinizden emin misiniz?") == false)
            return;
        deletePersonelAjax(personelId);
    }
    function deletePersonelAjax(personelId) {
        $.ajax({
            url: '/Personel/DeletePersonelAjax',
            data: {
                personelId: personelId
            },
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                getAllPersonelAjax();
            }
        });
    }
    function getAllPersonelAjax() {
        $.ajax({
            url: '/Personel/GetAllPersonelAjax',
            data: {

            },
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                var JSONData = eval(data);
                $("#tblPersoneller").children().remove();
                $('#tblPersoneller').append(
                     '<thead><tr>' +
                        '<th>Ad</th>' +
                        '<th>Soyad</th>' +
                        '<th>Email</th>' +
                        '<th>Kullanıcı Adı</th>' +
                        '<th>Şifre</th>' +
                        '<th>Aktif mi?</th>' +
                        '<th>Düzenle</th>' +
                        '<th>Sil</th>' +
                    ' </tr></thead>');
                $.each(JSONData, function (index, itemData) {

                    $('#tblPersoneller').append(
                        '<tr>' +
                            '<td>' + itemData.Ad + '</td>' +
                            '<td>' + itemData.Soyad + ' </td>' +
                            '<td>' + itemData.Email + ' </td>' +
                            '<td>' + itemData.KullaniciAdi + ' </td>' +
                            '<td>' + itemData.Sifre + ' </td>' +
                            '<td>' + itemData.Aktif + ' </td>' +
                            '<td><a href="/Personel/Create/' + itemData.Id.toString() + '" class="various" data-fancybox-type="iframe">Düzenle</a></td>' +
                            '<td><a href="#" onclick="confirmDelete(' + itemData.Id.toString() + ')" >Sil</a></td>' +
                        '</tr>');
                });
            }
        });
    }

</script>
<p>
</p>
<a href='/Personel/Create' class='various' data-fancybox-type='iframe'>
    <img width="18" height="18" src="/Content/IconImages/plus.png" /></a>
<table id="tblPersoneller" width="100%" class="bordered">
</table>
